import { useRouter } from "vue-router";

/**
 * 一些实现好的router跳转函数,需要提供router
 * @param {*} router
 * @returns
 */
export default function routerJump() {
  /**
   * 根据 id跳转到badge索引页 默认:动态列表
   * TODO: 预备废弃，进行分类具体实现
   */
  const router = useRouter();
  /**
   * 跳转到文章列表
   */
  const to_article_list = () => {
    return toArticleList(router);
  };
  /**
   * 跳转到动态列表
   */
  const to_essay_list = () => {
    return toEssayList(router);
  };
  const to_badge_content = (badge_id) => {
    return toBadgeContent(router, badge_id, "essay");
  };
  /**
   * 跳转到 标签内容页 并切到 文章页面
   */
  const to_badge_essay = (badge_id) => {
    return toBadgeContent(router, badge_id, "essay");
  };
  /**
   * 跳转到 标签内容页 并切到 文章页面
   */
  const to_badge_article = (badge_id) => {
    return toBadgeContent(router, badge_id, "article");
  };
  /**
   * 根据 id跳转到badge索引页 默认:动态列表
   * TODO: 预备废弃，进行分类具体实现
   */
  const to_collection_content = (collection_id) => {
    return toCollectionContent(router, collection_id, "article");
  };
  /**
   * 跳转到 集合内容页 并切到 文章页面
   */
  const to_collection_article = (collection_id) => {
    return toCollectionContent(router, collection_id, "article");
  };
  /**
   * 跳转到 集合内容页 并切到 动态页面
   */
  const to_collection_essay = (collection_id) => {
    return toCollectionContent(router, collection_id, "essay");
  };
  /**
   * 根据 动态id 跳转到 动态详情 页
   */
  const to_essay_detail = (essay_id) => {
    return toEssayDetail(router, essay_id);
  };
  const to_article_detail = (article_id) => {
    return toArticleDetail(router, article_id);
  };
  const to_article_edit = (article_id) => {
    return toArticleEdit(router, article_id);
  };
  /**
   * 根据 动态id 跳转到 动态编辑 页
   * id 为 -1时 ，启用创 建模式
   */
  const to_essay_edit = (essay_id) => {
    return toEssayEdit(router, essay_id);
  };
  /**
   *
   * @param {*} user_id 暂不支持
   * @returns
   */
  const to_userspace = () => {
    return toUserSpace(router);
  };
  /**
   * 根据浏览记录 返回 上一页
   */
  const go_back = () => {
    return GoBack(router);
  };

  const go_404 = () => {
    return Go404(router);
  };
  const go_home = () => {
    return GoHome(router);
  };
  const go_test = () => {
    return GoTest(router);
  };
  return {
    go_home,
    go_404,
    go_back,
    go_test,

    to_essay_list,
    to_essay_detail,
    to_essay_edit,

    to_badge_content,
    to_badge_essay,
    to_badge_article,

    to_collection_content,
    to_collection_essay,
    to_collection_article,

    to_article_list,
    to_article_detail,
    to_article_edit,

    to_userspace,
  };
}

const GoTest = (router) => {
  router.push({
    name: "TestPage",
  });
};

const GoHome = (router) => {
  router.push({
    name: "home",
  });
};

const Go404 = (router) => {
  router.push({
    name: "404",
  });
};

const GoBack = (router) => {
  router.go(-1);
};

const toEssayList = (router) => {
  router.push({
    name: "EssayListView",
  });
};

const toArticleDetail = (router, article_id) => {
  router.push({
    name: "ArticleDetailsView",
    params: { id: article_id },
  });
};

const toUserSpace = (router) => {
  router.push({
    name: "UserSpaceView",
  });
};

const toArticleList = (router) => {
  router.push({
    name: "ArticlesListView",
  });
};

const toArticleEdit = (router, article_id) => {
  router.push({
    name: "ArticleEditView",
    params: {
      id: article_id,
    },
  });
};

const toBadgeContent = (router, badge_id, type) => {
  router.push({
    name: "BadgeContentView",
    params: { id: badge_id, type: type },
  });
};

const toCollectionContent = (router, collection_id, type) => {
  router.push({
    name: "CollectionContentView",
    params: {
      id: collection_id,
      type: type,
    },
  });
};

const toEssayDetail = (router, essay_id) => {
  router.push({
    name: "EssayDetailsView",
    params: { id: essay_id },
  });
};

const toEssayEdit = (router, essay_id) => {
  router.push({
    name: "EssayEditView",
    params: { id: essay_id },
  });
};
